package com.le.admin.current.api.login;

import com.google.protobuf.ServiceException;
import com.le.common.basic.domin.AjaxResult;
import com.le.core.login.Service.LoginService;
import com.le.core.login.domin.PasswordLoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 账号密码
 */
@RestController
@RequestMapping("/password")
public class PasswordLoginController {

    @Autowired
    private LoginService<PasswordLoginUser> loginService;

    /**
     * 登录
     * @param passwordLoginUser
     * @return
     * @throws ServiceException
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody PasswordLoginUser passwordLoginUser) throws ServiceException {
        return AjaxResult.success().put("token",loginService.login(passwordLoginUser));
    }

    /**
     * 修改密码
     * @param passwordLoginUser
     * @return
     * @throws ServiceException
     */
    @PostMapping("/updatePassword")
    public AjaxResult updatePassword(@RequestBody PasswordLoginUser passwordLoginUser) throws ServiceException {
        return AjaxResult.success().put("token",loginService.login(passwordLoginUser));
    }

    /**
     * 注册
     * @param passwordLoginUser
     * @return
     * @throws ServiceException
     */
    @PostMapping("/register")
    public AjaxResult register(@RequestBody PasswordLoginUser passwordLoginUser) throws ServiceException {
        return AjaxResult.success(loginService.register(passwordLoginUser));
    }

}
